/**
 * 功能描述�?
 */

define(function (require, exports, module) {
	var aw = require("ajaxwrapper");
	
    module.exports = {
        checkData : function(params, widget){
        	widget.show([".J-form",".J-detailgrid",".J-roomeditgrid"]).hide([".J-grid"]);
			widget.get("subnav").hide(["save", "add", "status", "startDate"]).show(["return"]);
        	var form = widget.get("form");
        	form.setDisabled(true);
        	form.setData(params.planItemGroup);
        	form.setValue("year", params.planItemGroup.planItem.startDate);
        	var detailgrid = widget.get("detailgrid");
        	var roomeditgrid = widget.get("roomeditgrid");
        	aw.ajax({
        		url : "api/signupregister/query",
        		data : {
        			"planItemGroup" : params.planItemGroup.pkPlanItemGroup,
        			"validatePrivilege" : false,
        			fetchProperties : "pkSignUpRegister,version,member," +
							"personalInfo.idNumber,personalInfo.pkPersonalInfo," +
							"personalInfo.name,personalInfo.version,personalInfo.sex.*," +
							"personalInfo.mobilePhone,contactName,contactPhone,signUpDate,"+
							"planItemGroup.signUpRoomTypeCounts.*,planItemGroup.signUpRoomTypeCounts.roomType.name," +
							"planItemGroup.signUpRoomTypeCounts.roomType.pkRoomType"
        		},
        		dataType : "json",
        		success : function(datas){
        			if(datas.length != 0){
        				form.setValue("signUpNumber", datas.length);
        				detailgrid.setData(datas);
        				roomeditgrid.setData(datas[0].planItemGroup.signUpRoomTypeCounts);
        				roomeditgrid.get("model").allowEdit=false;
        				roomeditgrid.get("model").allowAdd=false;
        			}
        		}
        	})
        },
        
        editData : function(params, widget){
        	widget.set("pkSignList", []);
        	widget.show([".J-form",".J-editgrid",".J-roomeditgrid"]).hide([".J-grid"]);
			widget.get("subnav").hide(["add", "status", "startDate"]).show(["save", "return"]);
        	var form = widget.get("form");
        	var roomeditgrid = widget.get("roomeditgrid");
        	form.setData(params.planItemGroup);
        	form.setDisabled(false);
        	form.setValue("year", params.planItemGroup.planItem.startDate);
        	form.setValue("checkInStatus", params.planItemGroup.checkInStatus.key);
        	var editgrid = widget.get("editgrid");
        	aw.ajax({
        		url : "api/signupregister/query",
        		data : {
        			"planItemGroup" : params.planItemGroup.pkPlanItemGroup,
        			"validatePrivilege" : false,
        			fetchProperties : "pkSignUpRegister,version,member," +
        					"personalInfo.idNumber,personalInfo.pkPersonalInfo," +
        					"personalInfo.name,personalInfo.version,personalInfo.sex.*," +
        					"personalInfo.mobilePhone,contactName,contactPhone,signUpDate,"+
        					"planItemGroup.signUpRoomTypeCounts.*,planItemGroup.signUpRoomTypeCounts.roomType.pkRoomType," +
        					"planItemGroup.signUpRoomTypeCounts.roomType.name"
        		},
        		dataType : "json",
        		success : function(datas){
        			if(datas.length != 0){
        				form.setValue("signUpNumber", datas.length);
        				editgrid.setData([]);
        				editgrid.setData(datas);
        				roomeditgrid.setData([]);
        				roomeditgrid.setData(datas[0].planItemGroup.signUpRoomTypeCounts);
        				roomeditgrid.get("model").allowEdit=true;
        				roomeditgrid.get("model").allowAdd=true;
        			}
        		}
        	})
        },
    };
});
